import "package:flutter/material.dart";
import 'package:oktoast/oktoast.dart';

import './page0/index.dart';
import './page1/index.dart';
import './page2/index.dart';
import './page3/index.dart';
import './page4/index.dart';

class CalendarPage extends StatefulWidget {
    final String text;
    
    CalendarPage({Key key, this.text}) : super(key: key);
    
    @override
    State<StatefulWidget> createState() {
        return new _CalendarPageState();
    }
}

class _CalendarPageState extends State<CalendarPage> with TickerProviderStateMixin {
    
    @override
    void initState() {
        super.initState();
    }
    
    @override
    void dispose() {
        super.dispose();
    }
    
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: PreferredSize(
                preferredSize: Size.fromHeight(36.0), // here the desired height
                child: AppBar(
                    centerTitle: true,
                    elevation: 0.5,
                    titleSpacing: 0.0,
                    title: Text(widget.text),
                ),
            ),
            body: SingleChildScrollView(
                child: Container(
                    margin: EdgeInsets.symmetric(horizontal: 16.0),
                    child: Column(
                        // mainAxisSize: MainAxisSize.max,
                        children: <Widget>[
                            Container(
                                height: 100,
                                width: double.infinity,
                                margin: EdgeInsets.only(top: 16),
                                decoration: BoxDecoration(
                                    color: Color(0xFFFFE403),
                                    borderRadius: BorderRadius.all(
                                        Radius.circular(5),
                                    ),
                                ),
                                child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: <Widget>[
                                        Text('今日の努力は明日の成功を',
                                            style: TextStyle(
                                                color: Colors.black
                                            ),
                                        ),
                                        Text('今天的努力造就明天的成功',
                                            style: TextStyle(
                                                color: Colors.black
                                            ),
                                        ),
                                    ],
                                ),
                            ),
                            newContainer('实例零', context, 0),
                            /*newContainer('实例一', context, 3),
                            newContainer('实例二', context, 2),
                            newContainer('实例三', context, 1),
                            newContainer('实例四', context, 4),*/
                        ],
                    ),
                ),
            ),
        );
    }
    
    toast(label) {
        showToast(
            label,
            duration: Duration(seconds: 2),
            position: ToastPosition.center,
            backgroundColor: Colors.black.withOpacity(0.8),
            radius: 3.0,
            textPadding: EdgeInsets.symmetric(vertical: 6.0, horizontal: 12.0),
            textStyle: TextStyle(fontSize: 18.0),
        );
    }
    
    Widget newContainer(text, context, page) {
        return GestureDetector(
            child: Container(
                height: 100,
                width: double.infinity,
                margin: EdgeInsets.only(top: 16),
                decoration: BoxDecoration(
                    color: Color(0xFFFFE403),
                    borderRadius: BorderRadius.all(
                        Radius.circular(5),
                    ),
                ),
                child: Center(
                    child: Text(text),
                ),
            ),
            onTap: () {
                MaterialPageRoute router;
                switch (page) {
                    case 0 :
                        router = new MaterialPageRoute(builder: (context) => CalendarPage0(text: text));
                        break;
                    case 1 :
                        router = new MaterialPageRoute(builder: (context) => CalendarPage1(text: text));
                        break;
                    case 2 :
                        router = new MaterialPageRoute(builder: (context) => CalendarPage2(text: text));
                        break;
                    case 3 :
                        router = new MaterialPageRoute(builder: (context) => CalendarPage3(text: text));
                        break;
                    case 4 :
                        router = new MaterialPageRoute(builder: (context) => CalendarPage4(text: text));
                        break;
                }
                Navigator.push(context, router); //点击
            },
        );
    }
}
